home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr05
/
v12n13.zip
/
FIND.ZIP
/
FIND.DOC
< prev
next >
Wrap
Text File
|
1993-06-15
|
19KB
|
369 lines
FIND.DLL (VERSION 1.0) Copyright (c) 1993 Douglas Boling
-------------------------------------------------------------------------
First Published in PC Magazine July 1993 (Utilities)
-------------------------------------------------------------------------
FIND.DLL: A Text-Search Utility for Windows 3.1
BY DOUGLAS BOLING
FIND is a Windows 3.1 utility that lets you scan through a
single file, a set of files, or an entire partition and find all
occurrences of a given string. FIND can search in the background, so
you can continue to work on other tasks and instead of being a
standalone program, it seamlessly integrates itself into the Windows
File Manager. In this way, the services provided by FIND supplement the
already-powerful File Manager. Once installed, FIND becomes simply an
additional item on the File Manager menu.
USING FIND
To install FIND, copy the FIND.DLL file into a directory on your
hard disk. You should then edit the File Manager's WINFILE.INI file,
adding the following line to its [AddOns] section:
Text Search Extension=d:\path\FIND.DLL
For example, because I put FIND in my \WINDOWS\UT directory on
my D: drive, I entered
Text Search Extension=D:\WINDOWS\UT\FIND.DLL
Note that if your WINFILE.INI doesn't already have an [AddOns]
section, you must add it, on a line by itself. If the whole idea of
editing .INI files is new to you, see the sidebar (below)
`How to Install FIND.DLL''
Once FIND is installed, start the File Manager. You will see that
an extra menu item--Find--has been added on the main menu line. For a
quick test, select a file in the File Manager window, click on the
FindText menu item, type in the text to be found, and either press
Enter or click the Find button. FIND will then display a list of all
occurrences of that text string in the file you selected.
Since FIND is an extension of the File Manager, you can use the File
Manager to select the files you want examined. To select a file or
directory, simply click on it. If you hold down the Ctrl key while
making a selection the new file or directory will be added to the
currently selected list. Holding down the Shift key selects all files
between the current selection and the new selection. Note, however,
that multiple selections can be made only from the file list side of
the directory window.
Using the mouse or Alt-N to select the Find menu item on the File
Manager's main menu reveals the three-item FIND menu. Its first item,
Text, brings up FIND's Text Search dialog box. The text to be found is
entered in the edit box in the top-left corner. To its right is a
combo box that contains a list of the files you selected to search in
the File Manager window. If you change your mind you can enter a new
file specification directly in the combo box. This will remove any
previous selections.
The first check box at the bottom of the dialog box lets you tell
FIND to ignore the case of the text during the search. An X in the
second check box tells FIND to search through files contained in any
subdirectories below the current directory. If you set the directory
selection to the root directory and then check the Search Subdirectories
box, FIND will look for matching text in every file on the disk.
Pressing the Attributes button displays a dialog box that lets you
restrict the type of files to be searched. By default, FIND looks at
all files that match the filename specification. By using the
Attributes dialog, however, you can limit the search to files that
have the desired file attributes. There's usually no point in having
FIND waste its time going through the hidden files or system files.
Hitting Enter or clicking the Find button starts the search. FIND
will display the name of the file it is currently examining in the title
bar of the dialog box. This allows you to monitor the progress of the
search. When FIND finds the matching text, that line from the file is
displayed in the list box, together with the filename and the line
number within the file. If the file is not a pure ASCII text file,
FIND displays the offset into the file rather than the line number of
the matched text.
When you start a search, the Find button changes to read ``Stop.''
Pressing the Stop button immediately aborts the search. When a search
is stopped or has been completed, the button changes back to Find.
Since FIND performs its search in the background, you can continue to
work with programs other than the File Manager while the search is
taking place. The only limitation here is that you cannot switch to
a full-screen DOS box that has the Exclusive tasking option set.
If you do, FIND (along with all your other Windows programs) will be
suspended until you switch back to the desktop. The only remaining
button on the dialog box is the Cancel button.
The other two items on the main FIND menu are Files and About Find.
Selecting the Files menu displays the same dialog you could access from
the File Manager's FileSearch menu. I simply reduplicated it here to
let you use it as part of FIND's search operations. The final menu
selection, About Find, contains the usual author and copyright
information.
FILE MANAGER EXTENSIONS
The Windows 3.1 File Manager is much improved over its Windows 3.0
predecessor. Along with performance enhancements, Microsoft provided
a documented method for adding new functions to the File Manager.
The interface is described in the documentation that accompanies the
Microsoft Windows Software Development Kit (SDK), Borland's C++ 3.1
compiler, and other Windows 3.1 development environments. Fortunately,
the interface is relatively straightforward--for a Microsoft-defined
interface. Before discussing how FIND works in detail, it's good to
begin with File Manager extensions in general.
A File Manager extension must be implemented as a dynamic link
library (DLL) that contains an external entry point with the name
FMExtensionProc. When the File Manager is launched, it looks in the
[AddOns] section of its WINFILE.INI file for the names of any extension
DLLs. The File Manager reads the names listed there and loads each DLL
into memory. If a listed DLL cannot be found, the File Manager does
not display an error; it just proceeds to the next extension in the
list. This allows an extension to be removed simply by deleting the
DLL, although it is good practice to delete the [AddOns] entry as well.
Communication between the File Manager and an extension DLL is
performed through messages. When the File Manager wants to send a
message to an extension, it does not send the message to the
extension's window; instead, it calls FMExtensionProc. When the
extension wants to send a message to the File Manager, it uses the
standard Windows SendMessage() function to send a message back to the
File Manager window. The File Manager will respond correctly only to
messages sent from the FMExtensionProc function. Unfortunately, this
means that programs other than extensions cannot use these messages
to query the File Manager for information.
The File Manager calls FMExtensionProc with three parameters: the
handle of the File Manager window, a number indicating the message type,
and an lParam parameter that contains message-specific information.
Figure 1 (below) lists the messages used to communicate between the File
Manager and the extension. The File Manager also calls the
FMExtensionProc when the user selects any of the extension's menu items.
When the File Manager loads an extension DLL, it sends an
FMEVENT_ LOAD message to the extension. The lParam parameter contains
a pointer to an FMS_LOAD structure. Figure 2 (below) contains the
C-style definition for FMS_LOAD and for the other structures used in
the File Manager extension interface. When the extension is called,
the only field that is filled in by the File Manager is the wMenuDelta
field, which I'll discuss shortly.
Before returning from the FMEVENT_LOAD call, the extension must fill
in the dwSize, szMenuName and hMenu fields in the FMS_LOAD structure.
The first field, dwSize, is a (rather optimistically large) double-word
parameter that contains the size of the structure. The szMenuName
parameter is the menu name that the File Manager will use to label the
extension's menu on the File Manager's main menu. In keeping with
Windows standards, this string may contain an ampersand (&) character
preceding the character to be underlined in the menu item.
The hMenu field is filled with the handle of the extension submenu
to be displayed when the user selects the extension's main menu item.
Normally, the extension uses a LoadMenu call to load this menu from its
resource information. The items in an extension's menu must have IDs in
the range of 1 to 99. When the user selects one of the extension's menu
items, the File Manager calls FMExtensionProc with a message number set
to the ID value of the menu item. Thus, a File Manager extension
processes its menu selections in FMExtensionProc, not--as in a typical
Windows program--in a WM_COMMAND message.
The documentation for the FM_EVENTLOAD message mistakenly indicates
that the extension should not return a value for this message. The
extension must return the hMenu value or the extension will not be
loaded. Fortunately, this documentation error is not duplicated in
the example shown in the File Manager extension overview.
FMEVENT_INITMENU message is sent to the extension when the user selects
the extension's main menu item on the File Manager menu. The message
is sent before the extension menu is displayed, and it allows the
extension to perform any menu initialization processing needed. Such
menu initializations might include disabling or checking menu items.
If the extension's menu contains submenus, these must also be initialized
at this time, as no other notifications are sent when the submenus are
displayed. The lParam parameter contains the extension's menu handle
in the high word and the wMenuDelta parameter in the low word.
The wMenuDelta parameter is a number that the extension must use
when manipulating its own menu items. When the File Manager loads
an extension, it selects a wMenuDelta value that is higher than all its
other menu IDs. It then adds this wMenuDelta value to the extension's
menu IDs so that they will be unique. When the user selects one of
these items, the File Manager sends its original menu ID from 1 through
99 to the extension, but if an extension needs to modify a menu directly,
it must use the wMenuDelta value to compute the real menu ID. Thus, for
example, FIND has three menu items, Text, Files, and About, which have
ID numbers 1, 2, and 3. To disable the Files menu item, the extension
would use
EnableMenuItem (hMenu, 2 + wMenuDelta, MF_BYCOMMAND | MF_GRAYED);
The hMenu parameter in this example is the handle to the extension menu.
The FMEVENT_SELCHANGE message is sent to the extension when the user
changes the selections in the File Manager window. This message allows
the extension to update its display with the new selections. The
lParam parameter is not used in this message.
The FMEVENT_USER_REFRESH message is sent when the user selects the
File Manager's WindowRefresh menu item. This message indicates that
the extension should update its menus and windows to reflect the
current situation. As with the FMEVENT_SELCHANGE message, the lParam
parameter is not used.
Finally, the FMEVENT_UNLOAD message is sent to the extension when
the File Manager unloads the extension DLL. This message allows the
extension to perform any cleanup needed before being removed from
memory. Again, the lParam parameter is not used. While the extension
can use this message for cleanup, the DLL's WEP (Windows exit procedure)
routine will also be called by Windows' KERNEL module just before the
DLL is unloaded from memory.
During any of the FMEVENT messages, the extension can send a number
of messages to the File Manager to query its current state. The
FM_GETDRIVEINFO message is used to return information about the
currently selected disk drive. This message is sent with SendMessage's
lParam parameter pointing to an FMS_GETDRIVEINFO structure; the wParam
parameter is not used. FMS_GETDRIVEINFO contains such information as
the drive's total space, free space, current path, volume name and
share name.
The FM_GETFILESELCOUNT message can be used to query the number of
items selected in the File Manager's directory and search windows.
The File Manager returns the number of selected files and directories
in the return value of SendMessage. Neither the wParam nor the lParam
parameters of SendMessage are used for this message.
Once an extension knows how many files have been selected, it can
send an FM_GETFILESEL message to retrieve each of their names. For
this message, wParam contains the index of the file in which the
extension is interested, and lParam points to an FMS_GETFILESEL
structure. When the message returns, the structure is filled with
information about the file, including its name, size, attributes, and
the date and time the file was created.
FM_GETSELCOUNTFN and FM_GETFILESELFN are similar to the
FM_GETSELCOUNT and FM_GETFILESEL messages except that they also return
information on selected files whose filenames are longer than the
standard 8.3 DOS format. Although DOS does not itself recognize these
long filenames, this support is provided for File Manager extensions
that may operate on network files with nonstandard filenames.
Depending on the type of window that currently has the focus in
the File Manager, the FM_GETFOCUS message returns one of four values.
The four window types are the directory portion of the directory window,
the tree portion of the directory window, the drive selection bar, and
the search results window.
The last two File Manager messages, FM_REFRESH_WINDOWS and
FM_RELOAD_EXTENSIONS, give the extension a little bit of control over
what is presented in the File Manager windows. The FM_REFRESH_WINDOWS
message can be sent to instruct the File Manager when you want to update
its windows. This comes in handy if an extension creates, deletes, or
moves files and wants the File Manager to display the state of the disk
accurately. If the wParam parameter is zero, the File Manager updates
the active window; otherwise all File Manager windows are updated.
The FM_RELOAD_EXTENSIONS message instructs the File Manager to unload
and then reload all of its extensions. The File Manager rereads its
WINFILE.INI file to see what extensions need to be reloaded. This
message is convenient when an extension wants to unload itself. It can
remove its entry from WINFILE.INI and then send the FM_RELOAD_EXTENSIONS
message to force the File Manager to reload all the other extensions.
---------------------------------------------------------------------------
DOUGLAS BOLING IS A CONTRIBUTING EDITOR TO PC MAGAZINE. HE CAN BE REACHED
ON PC MAGNET (72241,217) IN THE UTILITIES/TIPS FORUM (GO ZNT:TIPS), THE
TECHNICAL SUPPORT AREA FOR PC MAGAZINE UTILITIES.
---------------------------------------------------------------------------
How to Install FIND.DLL
In order to install the FIND utility, simply follow these step-by-step
instructions:
1. Copy the file FIND.DLL into your Windows (or another convenient)
directory.
2. Start Notepad by double-clicking on the Notepad icon in the
Accessories group.
3. Open the File Manager's .INI file by selecting the FileOpen menu
selection in Notepad and entering WINFILE.INI.
4. Find the [AddOns] section in the file. If there is no [AddOns]
section, go to the end of the file and enter [AddOns] on a line
of its own.
5. Just under that line, add the line
Text Search Extension=FIND.DLL
If you didn't place FIND.DLL in your Windows directory, include
the path to the DLL in the filename.
6. Save the file by selecting the FileSave menu item.
7. Close Notepad by selecting the FileExit menu item.
===========================================================================
File Manager Messages
Messages from the File Manager to the extension
Messages 1 to 99Sent when the user selects one of the extension's menu items.
FMEVENT_LOADSent when the File Manager loads the extension.
FMEVENT_INITMENUSent when the user selects the extension's main menu selection.
FMEVENT_SELCHANGESent when the user changes the selection in the File Manager's directory or search window.
FMEVENT_USER_REFRESHSent when the user clicks on the File Manager's Refresh Windows button.
FMEVENT_UNLOADSent when the File Manager unloads the extension.
Message from the extension to the File Manager
FM_GETDRIVEINFOReturns information about the currently selected disk drive.
FM_GETSELCOUNTReturns the number of selections in the File Manager window.
FM_GETFILESELReturns directory entry information for a selected file.
FM_GETSELCOUNTFNSame as FM_GETSELCOUNT except that the count includes any selections with long filenames.
FM_GETFILESELFNSame as FM_GETFILESEL except that the filename returned may be longer than the standard 8.3 file-naming convention allows.
FM_GETFOCUSReturns the type of the File Manager window with the active focus.
FM_REFRESH_WINDOWSTells the File Manager to refresh its windows.
FM_RELOAD_EXTENSIONSTells the File Manager to unload then reload all its extensions.
Figure 1: These messages are used to communicate between the File Manager and a File Manager extension.
==============================================================================
Structures Used in the File Manager Extension Interface
typedef struct FMS_LOAD
DWORD dwSize;
char szMenuName[MENU_TEXT_LEN];
HMENU hMenu;
UINT wMenuDelta;
FMS_LOAD;
typedef struct FMS_GETDRIVEINFO
DWORD dwTotalSpace;
DWORD dwFreeSpace;
char szPath[260];
char szVolume[14];
char szShare[128];
FMS_GETDRIVEINFO, FAR *LPFMS_GETDRIVEINFO;
typedef struct FMS_GETFILESEL
UINT wTime;
UINT wDate;
DWORD dwSize;
BYTE bAttr;
char szName[260];
FMS_GETFILESEL;
Figure 2: The C-style definitions for FMS_LOAD, FMS_GETDRIVEINFO, and
FMS_GETFILESEL, which are used in the File Manager extension interface.
=======================================================================